# Makefile for httpd

# CONFIGURE: Some systems don't need -lcrypt, and indeed they get an
# error if you try to link with it.  If you get an error about libcrypt
# not found, try commenting out this definition.
CRYPT_LIB =    -lcrypt

# CONFIGURE: If you want to compile in support for https, uncomment these
# definitions.  You will need to have already built OpenSSL, available at
# http://www.openssl.org/  Make sure the SSL_TREE definition points to the
# tree with your OpenSSL installation - depending on how you installed it,
# it may be in /usr/local instead of /usr/local/ssl.

SSL_LIBS =	-lssl -lcrypto
#CC =		cc

CFLAGS =	-O -ansi -pedantic -U__STRICT_ANSI__ -Wall -Wpointer-arith -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wno-long-long
LDFLAGS =	-s
LDLIBS =	$(CRYPT_LIB) $(SSL_LIBS) 

all:		mime_encodings.h mime_types.h httpd

httpd:	httpd.o match.o tdate_parse.o data_exchange.o
	$(CC) $(LDFLAGS) httpd.o match.o tdate_parse.o data_exchange.o $(LDLIBS) -o httpd

httpd.o:	httpd.c match.h tdate_parse.h mime_encodings.h mime_types.h data_exchange.h
	$(CC) $(CFLAGS) -c httpd.c data_exchange.c

match.o:	match.c match.h
	$(CC) $(CFLAGS) -c match.c

tdate_parse.o:	tdate_parse.c tdate_parse.h
	$(CC) $(CFLAGS) -c tdate_parse.c

mime_encodings.h: mime_encodings.txt
	rm -f mime_encodings.h
	sed < mime_encodings.txt > mime_encodings.h \
	  -e 's/#.*//' -e 's/[ 	]*$$//' -e '/^$$/d' \
	  -e 's/[ 	][ 	]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/'

mime_types.h: mime_types.txt
	rm -f mime_types.h
	sed < mime_types.txt > mime_types.h \
	  -e 's/#.*//' -e 's/[ 	]*$$//' -e '/^$$/d' \
	  -e 's/[ 	][ 	]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/'

cert:		httpd.pem
httpd.pem:	httpd.cnf
	openssl req -new -x509 -days 3650 -nodes -config httpd.cnf -out httpd.pem -keyout httpd.pem
	openssl x509 -subject -dates -fingerprint -noout -in httpd.pem
	chmod 600 httpd.pem

clean:
	rm -f httpd mime_encodings.h mime_types.h httpd.rnd *.o

